<?php
include "./include/om_config.inc";
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{	
  $smarty = new SmartyWWW();
 
  $filePath = '';
  $fileName = '';
  
  if(isset($_POST['submitBtn']))
  {
    $uploaddir = dirname($_POST['filePath']);

    $uploadfile = $uploaddir . basename($_FILES['fileName']['name']);
    
    $target_path = './bhavcopiesfo';
    $target_path = $target_path ."/". basename( $_FILES['fileName']['name']);
    $_FILES['fileName']['tmp_name']; // temp file
    
    $oldfile =  basename($_FILES['fileName']['name']);

    // getting the extention

    $pos = strpos($oldfile,".",0);
    $ext = trim(substr($oldfile,$pos+1,strlen($oldfile))," ");
    
    if(move_uploaded_file($_FILES['fileName']['tmp_name'], $target_path)) 
    {
      $selectgeneralf_o = "SELECT * FROM generalf_o";
      $resultgeneralf_o = mysql_query($selectgeneralf_o);
      if($resultgeneralf_o && mysql_num_rows($resultgeneralf_o) == 0)
      {
      	$insertQuery ="INSERT INTO generalf_o (filePath,fileName) 
      	               VALUES ('bhavcopiesfo','".$_FILES['fileName']['name']."')";
      	$resultQuery = mysql_query($insertQuery);
      }
      if(mysql_num_rows($resultgeneralf_o) != 0)
      {
      	$updateQuery = "UPDATE generalf_o SET filePath='bhavcopiesfo',
                        fileName='".$_FILES['fileName']['name']."'";
      	$updateResult = mysql_query($updateQuery);
    	}
      header("Location: storeBhavCopyF_O.php?exc=F_O");

/////////////////////////////////////////////// Start

/////////////////////////////////////////////// End
    } 
    else
      echo "There was an error uploading the file, please try again!";
  }
  $selectQuery = "SELECT * FROM general";
  $selectResult = mysql_query($selectQuery);
  if($selectRow = mysql_fetch_array($selectResult))
  {
    $filePath = $selectRow['filePath'];
    $fileName = $selectRow['fileName'];
  }
  
  $headMenu  = "<B>Tips : &nbsp;&nbsp;</B><A href='./txtFileF_O.php?exc=F_O'>SubmitF_O </A>&nbsp;&nbsp;&nbsp;";

  $smarty->assign("headMenu", $headMenu);
}
?>
<BODY><br>

<H1><CENTER><FONT color="red">TIPS</FONT></CENTER></H1><HR>

<CENTER>
  <FORM enctype="multipart/form-data" action="" name="form1" method="POST"> 
	<a href="index.php">Home</a>&nbsp;&nbsp;&nbsp;	<a href="bhavCopyListF_O.php">List F_O</a>
	&nbsp;&nbsp;&nbsp;	<a href="bhavCopyListF_O2.php">List F_O All</a>&nbsp;&nbsp;&nbsp;<br /><br />
	<input type="hidden" name="exc" value="F_O">
<INPUT size="60" type="hidden" name="filePath"><BR>
File Name: <INPUT name="fileName" type="file" onChange="document.form1.filePath.value=document.form1.fileName.value;">
<INPUT type="submit" name="submitBtn" value="Submit File"> 
</FORM>
</CENTER>
